package algorithm;

public class leetcode_0968 {
    public int minCameraCover(TreeNode root) {
        int[] result=new int[1];
        int a=num(root,result);
        if(a==0) return result[0]+1;
        return result[0];
    }
    public int num(TreeNode node,int[] result){
        if(node==null) return 2;
        int left=num(node.left,result);
        int right=num(node.right,result);
        if(left==2&&right==2) return 0;
        if(left==0||right==0) {result[0]+=1;return 1;}
        if(left==1||right==1) return 2;
        else return 2;
    }
}
